<template>
  <!--会签管理-审批汇总-->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="项目">
              <a-select :options="levelOneOptions" placeholder="请选择项目" v-model="queryParam.projectId"> </a-select>
            </a-form-item>
          </a-col>

          <a-col :xl="7" :lg="7" :md="8" :sm="24">
            <a-form-item label="单据类型">
              <!-- <a-select style="width: calc(100% - 240px)" placeholder="请选择单据类型" v-model="queryParam.billsType">
                <a-select-option value="1">人事</a-select-option>
                <a-select-option value="3">财务</a-select-option>
                <a-select-option value="2">行政</a-select-option>
                <a-select-option value="4">合同</a-select-option>
                <a-select-option value="5">采购</a-select-option>
              </a-select> -->
              <j-dict-select-tag placeholder="请选择单据类型" v-model="queryParam.billsType" style="width: calc(100% - 240px)"
                dictCode="bills_type"></j-dict-select-tag>
              <a-input style="width: 230px; margin-left: 10px" placeholder="请输入单据名称" v-model="queryParam.billsTemplateName"></a-input>
            </a-form-item>
          </a-col>

          <a-col :xl="8" :md="10" :sm="12">
            <a-form-item label="提交时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
              <j-date
                v-model="queryParam.queryStartTime"
                :showTime="true"
                date-format="YYYY-MM-DD "
                style="width: 25%"
                placeholder="请选择开始时间"
              ></j-date>
              <span style="width: 10px">~</span>
              <j-date
                v-model="queryParam.queryEndTime"
                :showTime="true"
                date-format="YYYY-MM-DD"
                style="width: 25%"
                placeholder="请选择结束时间"
              ></j-date>
            </a-form-item>
          </a-col>

          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="审批编号">
              <a-input placeholder="请输入" v-model="queryParam.approvNumber"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="审核状态">
              <a-select placeholder="请选择状态" v-model="queryParam.status">
                <a-select-option value="0">未提交</a-select-option>
                <a-select-option value="1">待审核</a-select-option>
                <a-select-option value="2">全员已通过</a-select-option>
                <a-select-option value="3">已驳回</a-select-option>
                <a-select-option value="4">已撤销</a-select-option>
                </a-select
              >
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator"></div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="status" slot-scope="text, record">
          <!-- <a @click="handleEdit(record)">编辑  </a> -->
          <a v-if="record.status == 0" style="color: orange;">未提交 </a>
          <a v-if="record.status == 1" style="color: blue;">审核中</a>
          <a v-if="record.status == 2" style="color: green;"> 全员已通过 </a>
          <a v-if="record.status == 3" style="color: red;">已驳回 </a>
          <a v-if="record.status == 4" style="color: gray;">已撤销 </a>
        </span>
        <template slot="isSubmit" slot-scope="text, record">
          <div :style="{color:record.isSubmit == '0'?'green':'blue'}">{{record.isSubmit == '0'?'否':'是'}}</div>
        </template>
        <span slot="action" slot-scope="text, record">
          <!-- 详情 -->
          <div v-if="record.status != 0" style="display: inline-block;margin-right: 5px;">
            <a @click="handleDetail(record,'detail')" v-if="record.status != 0">详情</a>
          </div>
		  <a @click="handleDayin(record)" v-if="record.status == 2">预览打印 </a>
        </span>
      </a-table>
    </div>
    <huiqian-print ref="modalForm1" @ok="modalFormOk"></huiqian-print>
    <huiqian-modal  ref="modalForm2" @ok="modalFormOk"></huiqian-modal>
    <huiqian-modal  ref="modalForm3" @ok="modalFormOk"></huiqian-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import huiqianPrint from './components/huiqianPrint.vue'
import huiqianModal from './components/huiqianModal.vue'
import { httpAction, getAction } from '@/api/manage'
export default {
  name: 'WtBrandList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    huiqianPrint,
    huiqianModal,
  },
  data() {
    return {
      description: '品牌记录表管理页面',
      // 表头
      columns: [
        {
          title: '审批编号',
          dataIndex: 'approvNumber',
          // key:'rowIndex',
          width: 50,
          align: 'center',
          // customRender:function (t,r,index) {
          //   return parseInt(index)+1;
          // }
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'proposerName',
        },
        {
          title: '项目',
          align: 'center',
          dataIndex: 'projectName',
        },
        {
          title: '提交时间',
          align: 'center',
          dataIndex: 'createTime',
        },
        {
          title: '标题',
          align: 'center',
          dataIndex: 'title',
        },
        {
          title: '单据名称',
          align: 'center',
          dataIndex: 'billsTemplateName',
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status',
          scopedSlots: { customRender: 'status' },
        },
        {
          title: '是否为重新提交',
          align: 'center',
          dataIndex: 'isSubmit',
          scopedSlots: { customRender: 'isSubmit' },
        },
        // {
        //   title:'附件资料',
        //   align:"center",
        //   dataIndex: 'attachment'
        // },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/countersign/wtCountersign/all/list',
        delete: '/wtBrand/delete',
        deleteBatch: '/wtBrand/deleteBatch',
        exportXlsUrl: '/wtBrand/exportXls',
        importExcelUrl: 'wtBrand/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
      levelOneOptions: [],
      treeData1: [],
      model: {
        id: '',
        status: '',
      },
      pageType:'', 
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    handleDetail: function (record, type) {
      console.log(222,record,type);
      this.$refs.modalForm2.title = '单据';
      this.$refs.modalForm2.pageType = type;
      this.$refs.modalForm2.billsTemplateName = record.billsTemplateName;
      this.$refs.modalForm2.receiptsModel = record.receiptsModel;
      this.$refs.modalForm2.edit(record);
      this.$refs.modalForm2.disableSubmit = true;
      
      /* if(record.billsTemplateName == '付款计划'){
        this.$refs.modalForm.title = '单据';
        this.$refs.modalForm.pageType = type;
        this.$refs.modalForm.edit(record);
        this.$refs.modalForm.disableSubmit = true
        
      }else if(record.billsTemplateName == '材料结算'){
        this.$refs.modalForm2.title = '单据'
        this.$refs.modalForm2.pageType = type;
        this.$refs.modalForm2.edit(record);
        this.$refs.modalForm2.disableSubmit = true
        
      }else if(record.billsTemplateName == '付款申请'){
        this.$refs.modalForm3.title = '单据'
        this.$refs.modalForm3.pageType = type;
        this.$refs.modalForm3.edit(record)
        this.$refs.modalForm3.disableSubmit = true
        
      }else if(record.billsTemplateName == '劳务结算'){
        this.$refs.modalForm4.title = '单据';
        this.$refs.modalForm4.pageType = type;
        this.$refs.modalForm4.edit(record);
        this.$refs.modalForm4.disableSubmit = true;
        
      }else if(record.billsTemplateName == '工程项目合同审批'){
        this.$refs.modalForm5.pageType = type;
        this.$refs.modalForm5.title = '单据'
        this.$refs.modalForm5.edit(record)
        this.$refs.modalForm5.disableSubmit = true;
      } */
      
    },
    handleDetail2(record, type){
      this.$refs.modalForm3.billsTemplateName = record.billsTemplateName;
      this.$refs.modalForm3.receiptsModel = record.receiptsModel;
      this.$refs.modalForm3.pageType = type;
      this.$refs.modalForm3.edit(record)
      if(type === 'anew'){
        this.$refs.modalForm3.title = '单据（重新提交）'
      }else{
        this.$refs.modalForm3.title = '单据'
      }
      
      /* if(record.billsTemplateName == '付款计划'){
        this.$refs.modalForm6.pageType = type;
        this.$refs.modalForm6.edit(record)
        if(type === 'anew'){
          this.$refs.modalForm6.title = '单据（重新提交）'
        }else{
          this.$refs.modalForm6.title = '单据'
        }
        
      }else if(record.billsTemplateName == '材料结算'){
        this.$refs.modalForm7.pageType = type;
        this.$refs.modalForm7.edit(record)
        if(type === 'anew'){
          this.$refs.modalForm7.title = '单据（重新提交）'
        }else{
          this.$refs.modalForm7.title = '单据'
        }
        
      }else if(record.billsTemplateName == '付款申请'){
        this.$refs.modalForm8.pageType = type;
        this.$refs.modalForm8.edit(record)
        if(type === 'anew'){
          this.$refs.modalForm8.title = '单据（重新提交）'
        }else{
          this.$refs.modalForm8.title = '单据'
        }
        
      }else if(record.billsTemplateName == '劳务结算'){
        this.$refs.modalForm9.pageType = type;
        this.$refs.modalForm9.edit(record)
        if(type === 'anew'){
          this.$refs.modalForm9.title = '单据（重新提交）'
        }else{
          this.$refs.modalForm9.title = '单据'
        }
        
      }else if(record.billsTemplateName == '工程项目合同审批'){
        this.$refs.modalForm10.pageType = type;
        this.$refs.modalForm10.edit(record);
        if(type === 'anew'){
          this.$refs.modalForm10.title = '单据（重新提交）'
        }else{
          this.$refs.modalForm10.title = '单据'
        }
      } */
    },
    handleDayin: function (record) {
      // console.log('fdeswa');
      this.$refs.modalForm1.edit(record)
      this.$refs.modalForm1.title = '审批记录单'
      this.$refs.modalForm1.disableSubmit = false
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      //加载数据 若传入参数1则加载第一页的内容
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() //查询条件
      this.loading = true
      getAction(this.url.list, params)
        .then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          this.loading = false
        })
      getAction(`/sys/sysDepart/getDepartByOrgType?orgType=1`).then((res) => {
        if (res.success) {
          this.treeData1 = []
          let treeList1 = res.result
          for (let a = 0; a < treeList1.length; a++) {
            let temp = treeList1[a]
            temp.isLeaf = temp.leaf
            this.treeData1.push(temp)
          }

          this.levelOneOptions = [...this.treeData1].map((v) => {
            return {
              ...v,
              value: v.id,
              label: v.departName,
            }
          })
        }
      })
    },
    handleCuiBan(id){
      var that = this;
      let params = {}
      params.id = id;
      //that.model.status = '4'
      httpAction('/countersign/wtCountersign/urgeOperator', params, 'post').then((res) => {
        if (res.success) {
          //重新计算分页问题
          that.reCalculatePage(1)
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    handleCheXiao(id) {
      var that = this
      that.model.id = id
      that.model.status = '4'
      httpAction('/countersign/wtCountersign/revocationOperator', this.model, 'post').then((res) => {
        if (res.success) {
          //重新计算分页问题
          that.reCalculatePage(1)
          that.$message.success(res.message)
          that.loadData()
        } else {
          that.$message.warning(res.message)
        }
      })
    },
    reCalculatePage(count){
      //总数量-count
      let total=this.ipagination.total-count;
      //获取删除后的分页数
      let currentIndex=Math.ceil(total/this.ipagination.pageSize);
      //删除后的分页数<所在当前页
      if(currentIndex<this.ipagination.current){
        this.ipagination.current=currentIndex;
      }
      console.log('currentIndex',currentIndex)
    },
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'categoryOneId', text: '一级分类id', dictCode: '' })
      fieldList.push({ type: 'string', value: 'categoryTwoId', text: '二级分类id', dictCode: '' })
      fieldList.push({ type: 'string', value: 'categoryThreeId', text: '三级分类id', dictCode: '' })
      fieldList.push({ type: 'string', value: 'name', text: '名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'introduce', text: '介绍', dictCode: '' })
      this.superFieldList = fieldList
    },
  },
}
</script>
  <style scoped>
@import '~@assets/less/common.less';
</style>